<template>
	<view class="page">
		<image src="../../static/register/top2.jpg" mode="widthFix" class="top" />
		<view class="location-container">
			<view class="left">
				<image src="../../static/register/location.png" mode="widthFix" class="location"></image>
				<text>代驾服务地点</text>
			</view>
			<view class="right">{{provinceName}} - {{cityName}}</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">入驻条件</text>
			</view>
			<view class="list">
				<view class="item">
					<text>1.</text>
					三年安全驾驶经验；
				</view>
				<view class="item">
					<text>2.</text>
					年龄23~55周岁；
				</view>
				<view class="item">
					<text>3.</text>
					无违法犯罪记录、无精神病史、无吸毒史，以及平台认为不适合代驾的其他历史证明；
				</view>
				<view class="item">
					<text>4.</text>
					有熟练驾车经验；
				</view>
				<view class="item">
					<text>5.</text>
					身体健康，无肢体残疾和大面积纹身；
				</view>
				<view class="item">
					<text>6.</text>
					需要提供身份证、驾驶证、直系亲属联系方式，并保存前述材料的真实合法性；
				</view>
			</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">入驻流程</text>
			</view>
			<view class="list">
				<view class="complex-item">
					<view class="left">01</view>
					<view class="right">
						<text class="item-title">在线注册账号</text>
						<text class="item-desc">在小程序完成注册</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">02</view>
					<view class="right">
						<text class="item-title">司机信息填写</text>
						<text class="item-desc">按照流程提交本人身份证、驾驶证</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">03</view>
					<view class="right">
						<text class="item-title">证件资料审核</text>
						<text class="item-desc">对提交证件进行审核</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">04</view>
					<view class="right">
						<text class="item-title">签署合同</text>
						<text class="item-desc">收到邮寄的合同后必须本人签署并寄回</text>
					</view>
				</view>
			</view>
		</view>
		<button class="btn" @tap="wxRegister" >司机注册</button>
		<!-- <button class="btn" open-type="getPhoneNumber" @getphonenumber="phoneRegister" >司机注册</button> -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
var QQMapWX = require('../../lib/qqmap-wx-jssdk.min.js');
var qqmapsdk;
export default {
	data() {
			return {
				code: null,
				// 获取所在市
				cityName:"未知",
				// 获取所在省
				provinceName: ""
			};
		},
		// 页面加载时执行一次
		onLoad() {
			// 在函数中有的时候this的指向会变，变为不是Vue实例对象
			const _this = this;
			
			_this.initQQMap();
			
			// 1.获取经纬度信息
			let location = _this.getLocation();
			_this.reverseGeocoder(location);
			// 2.获取城市信息
			
		},
		methods: {
			phoneRegister(e) {
				const _this = this;
				var phoneCode = e.detail.code
				wx.login({
				  success (res) {
					if (res.code) {
						console.log(res.code);
						_this.get("/driver/app/driver/register/" + res.code + "/" + phoneCode, (resp) => {
							if (resp.success) {
								uni.showToast({
									icon: "success",
									title: "注册成功，请登录",
								});
								// 设置一个1000毫秒后执行的定时器
								setTimeout(function() {
									//在起始页面跳转到test.vue页面并传递参数
									uni.navigateTo({
										url: '/pages/login/login'
									});
								}, 2000);
							} else {
								uni.showToast({
									icon: "error",
									title: resp.message,
								});
							}				  
						})                                          
					} else {                                      
					  console.log('注册失败！' + res.errMsg)       
					}                                             
				  }
				})
			},
			
			// 司机注册
			wxRegister() {
				const _this = this;
				
				uni.removeStorageSync("tokenName");
				uni.removeStorageSync("tokenValue");
				uni.removeStorageSync("permissions");
				uni.removeStorageSync("loginInfo");
				
				wx.login({
				  success (res) {
				    if (res.code) {
						console.log(res.code);
						_this.get("/driver/app/driver/register/" + res.code, (resp) => {
							if (resp.success) {
								uni.showToast({
									icon: "success",
									title: "注册成功，请登录",
								});
								// 设置一个1000毫秒后执行的定时器
								setTimeout(function() {
								    //在起始页面跳转到test.vue页面并传递参数
								    uni.navigateTo({
								    	url: '/pages/login/login'
								    });
								}, 2000);
							} else {
								uni.showToast({
									icon: "error",
									title: resp.message,
								});
							}				  
						})                                          
				    } else {                                      
				      console.log('登录失败！' + res.errMsg)       
				    }                                             
				  }
				})
			},
			// 1.获取经纬度信息
			getLocation(){
				uni.getLocation({
					type: 'wgs84',
					success: function (res) {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
						return res;
					}
				});
			},
			// 2.初始化腾讯地图对象
			initQQMap(){
				qqmapsdk = new QQMapWX({
					key: 'VJNBZ-XGTCN-OWNFW-SSLAR-PZ4PF-OBBIY' // 必填
				}); 
			},
			// 3.逆地址解析
			reverseGeocoder(location){
				const _this = this;
				qqmapsdk.reverseGeocoder({
					location: location,
					success:(res)=>{
						console.log(res);
						if(res.status == 0){
							_this.cityName = res.result.address_component.city;
							_this.provinceName = res.result.address_component.province;
						}else {
							uni.showToast({
								icon:"error",
								title:"获取地址失败!"
							})
						}
					}
				})
			}
			
		}
};
</script>

<style lang="less">
@import url('register.less');
</style>
